var stockGoodsLocaTable=null;
var stockGoodsExtTable=null;
/*
页面初始化
 */
$(function(){

    showstockGoodsLocaTab();
    $('a[data-toggle="tab"]').on('show.bs.tab',function (e) {
        debugger;
        switch ($(this).attr("id")){
            case  "localstor":
                showstockGoodsLocaTab();
                break;
            case "externalstor":
                showstockGoodsExtTab();
                break;
            default:
                break;
        }
    })
});

function showstockGoodsLocaTab() {
    if(stockGoodsLocaTable==null)    {
        stockGoodsLocaTable=$('#stockGoodsLocaTable').DataTable({
            "autoWidth": false,
            "processing": true,
            "serverSide": true,
            "dom": '<"bottom"rtflp>',
            "searching": false,
            "paging": false,
            "deferRender": true,
            "ordering": true,
            "ajax": {
                "url": "/stockGoods/getStockGoodsStorLocalInfo.action?goodsId="+$('#myid', window.parent.document).val()
            },
            "columns": [{
                "data": "storName",
                "orderable": true
            }, {
                "data": "totalQty",
                "orderable": true
            }, {
                "data": "stockQty",
                "orderable": true
            }, {
                "data": "junkQty",
                "orderable": true
            }, {
                "data": "available",
                "orderable": true
            },  {
                "data": "allotQty",
                "orderable": true
            }, {
                "data": "unallotQty",
                "orderable": true
            }, {
                "data": "logicStockoutQty",
                "orderable": true
            }, {
                "data": "onwayQty",
                "orderable": true
            }, {
                "data": "reserveQty",
                "orderable": true
            }],
            "footerCallback": function (tfoot, data, start, end, display) {
                var api = this.api();
                for (var i=1;i<=9;i++)
                $( api.column( i ).footer() ).html(
                    api.column( i ).data().reduce( function ( a, b ) {
                        return a + b;
                    }, 0 )
                );
            },
        });
        // 文字过长截断显示悬浮框
        $("#stockGoodsLocaTable").tooltip({
            selector: ".tooltip-column-detail-5",
            container: "body",
            title: function() {
                if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                    return $(this).text();
                }
            }
        });
    } else {
        stockGoodsLocaTable.draw();
    }
}



function showstockGoodsExtTab() {
    debugger;
    if(stockGoodsExtTable==null)
    {
        stockGoodsExtTable=$('#stockGoodsExtTable').DataTable({
            "autoWidth": false,
            "processing": true,
            "serverSide": true,
            "dom": '<"bottom"rtflp>',
            "searching": false,
            "paging": false,
            "deferRender": true,
            "ordering": true,
            "ajax": {
                "url": "/stockGoods/getStockGoodsStorExtInfo.action?goodsId="+$('#myid', window.parent.document).val()
            },
            "columns": [{
                "data": "storName",
                "orderable": true
            }, {
                "data": "totalCount",
                "orderable": true
            }, {
                "data": "stockCount",
                "orderable": true
            }, {
                "data": "junkCount",
                "orderable": true
            }, {
                "data": "sellCount",
                "orderable": true
            }, {
                "data": "available",
                "orderable": true
            }, {
                "data": "allotQty",
                "orderable": true
            }, {
                "data": "unallotQty",
                "orderable": true
            }, {
                "data": "canallotQty",
                "orderable": true
            }, {
                "data": "onwayQty",
                "orderable": true
            }, {
                "data": "reserveQty",
                "orderable": true
            }],
            "footerCallback": function (tfoot, data, start, end, display) {
                var api = this.api();
                for (var i=1;i<=10;i++)
                    $( api.column( i ).footer() ).html(
                        api.column( i ).data().reduce( function ( a, b ) {
                            return a + b;
                        }, 0 )
                    );
            },
        });
        // 文字过长截断显示悬浮框
        $("#stockGoodsLocaTable").tooltip({
            selector: ".tooltip-column-detail-5",
            container: "body",
            title: function() {
                if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                    return $(this).text();
                }
            }
        });
    } else {
        stockGoodsLocaTable.draw();
    }
}